<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	public function __construct(){
		parent::__construct();
	}
	
	public function index(){
	
		$data['page_html_title'] = "Admin Login1";
		$this->load->view('login',$data);
		
	}
	
	public function validate(){
	
		$data['page_html_title'] = "";
		
		
		$this->load->model('login_model');
        $query = $this->login_model->validate();
		$user = $query[0];
		
		$this->load->library('form_validation');
		$this->form_validation->set_rules('username', 'Username', 'trim|required');
		$this->form_validation->set_rules('adminpassword', 'Password', 'trim|required');
		if ($this->form_validation->run() == FALSE)	{
			$data['page_html_title'] = "Admin Login Error";
			$this->index();
		}else{
			if(isset($user->id)) {
				$data = array(
					'is_admin_loged' => true,
					'loaged_name' => $user->name,
                    'username' => $user->username,
                );
				$this->session->set_userdata($data);
				redirect('admin/desktop');
			}else{
				$data['page_html_title'] = "Admin Login Error";
			  	$this->index();
			}
		}
		
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>